#coding=utf-8

import json
from MZCCSpecialRuleHeader import *
from Model.MZCCSingleLineRuleItem import *
from Model.MZCCMulLineRuleItem import *

#获得单行规则列表
def mzccSingleLineRuleList(jsonFilePath):

    ruleArray = json.load(open(jsonFilePath, 'r'));

    singleRuleList = [];
    for tmpRuleDic in ruleArray:

        if 0 == tmpRuleDic["rule_type"]:
            tmpSinRule = MZCCSingleLineRuleItem();
            tmpSinRule.ruleId = tmpRuleDic["rule_id"].encode('utf-8');
            tmpSinRule.desc = tmpRuleDic["rule_desc"].encode('utf-8');
            tmpSinRule.rejectRe = tmpRuleDic["reject_re"].encode('utf-8');

            if 1 == tmpRuleDic["is_special_check"]:
                tmpFuncName = "mzcc_udrule_" + tmpRuleDic["rule_id"].encode('utf-8');
                tmpSinRule.udCheckFuncName = tmpFuncName;
            else:
                tmpSinRule.udCheckFuncName = "";

            singleRuleList.append(tmpSinRule);

    return singleRuleList;

#获取多行规则列表
def mzccMulLineRuleList(jsonFilePath):

    ruleArray = json.load(open(jsonFilePath, 'r'));

    mulRuleList = [];
    for tmpRuleDic in ruleArray:

        if 1 == tmpRuleDic["rule_type"]:
            tmpMulRule = MZCCMulLineRuleItem();
            tmpMulRule.ruleId = tmpRuleDic["rule_id"].encode('utf-8');
            tmpMulRule.desc = tmpRuleDic["rule_desc"].encode('utf-8');

            tmpMulRule.startRe = tmpRuleDic["start_re"].encode('utf-8');
            tmpMulRule.lineRecordRe = tmpRuleDic["line_num_update_re"].encode('utf-8');
            tmpMulRule.acceptRe = tmpRuleDic["accept_re"].encode('utf-8');
            tmpMulRule.rejectRe = tmpRuleDic["reject_re"].encode('utf-8');

            if 1 == tmpRuleDic["is_special_check"]:
                tmpFuncName = "mzcc_udrule_" + tmpRuleDic["rule_id"].encode('utf-8');
                tmpMulRule.udCheckFuncName = tmpFuncName;
            else:
                tmpMulRule.udCheckFuncName = "";

            mulRuleList.append(tmpMulRule);

    return mulRuleList;
